<!-- eslint-disable vue/multi-word-component-names -->
<template>
  <div style="width: 100%;">
    <div style="width: 100%;">
      <div style="display: flex; padding: 1px 15px;align-items: center;">
        <!-- 组件1 : 新增按钮 + 菜单名称 -->
        <el-button type="primary" @click="add">新建</el-button>
        <span style="margin-left: 10px; font-size: 20px;">角色</span>
        <div style="margin-left: auto;margin-right: auto;">
          <!-- 搜索框 -->
          <ISearch v-if="multipleSelection.length == 0" class="search-operation-container"></ISearch>
          <!-- 操作按钮组 -->
          <div v-else>
            <el-button type="primary" style="background-color: #f1edf0; color: #714B67;">
              {{ "(" + multipleSelection.length + ") 已选取" }}
            </el-button>
            <el-button type="primary">
              <el-icon>
                <Tools />
              </el-icon> &nbsp; 操作
            </el-button>
          </div>
        </div>
      </div>
    </div>
    <!-- 分割线 -->
    <el-divider border-style="dotted" />

    <div style="display: flex; height: 100vh;">
      <!-- 部门树 -->
      <!-- 表格列表 -->
      <div style="display: flex;flex-direction: column; height: auto;position: relative; width: 100%;flex: 1;">
        <el-table ref="multipleTableRef" :data="tableData" style="width: 100%" @selection-change="handleSelectionChange"
           @row-click="(row) => router.push({ path: '/setting-roles/add', query: { id: row.id } })">
          <el-table-column type="selection" width="55" />
          <el-table-column prop="roleName" label="角色名称" width=400 />
          <el-table-column prop="roleKey" label="编码" sortable width=650 />
          <el-table-column prop="dataScope" label="数据权限" width=600 />
          <el-table-column prop="status" label="状态" />
        </el-table>
        <!-- 分页 -->
        <div style="margin-top: 20px;">
          <IdooPagination :param="initPaginationParam" style="float:right ;margin-right: 25px;"
            @click-call-back="paginationCallBack"></IdooPagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue';
import IdooPagination from '@/components/base/pagination/index.vue'
import { Tools } from '@element-plus/icons-vue'
import ISearch from '@/components/base/search/index.vue'
import type { PaginationStructure } from '@/components/base/pagination';
import router from '@/router';
import { _getRoleList, type RoleInfo } from '@/api/generic/role/role-api';


//列表勾选得内容
const multipleSelection = ref<[]>([]);
//分页参数
const initPaginationParam = ref<PaginationStructure>();
//表格勾选
const handleSelectionChange = (val: []) => {
  console.log(val);
  multipleSelection.value = val;
}
const tableData = ref<RoleInfo[]>([]);

const paginationCallBack = (obj: object) => {
  console.log(obj);
}


//新增角色
const add = () => {
  router.push({
    path: '/setting-roles/add'
  })
}
onMounted(async () => {
  initPaginationParam.value = {
    pageSize: 80,
    totalNum: 235
  }

  await _getRoleList().then(res => {
    tableData.value = res.data.rows;
  }); 
});
</script>

<style scoped>
:deep(.el-divider--horizontal) {
  margin: 20px 0px 0px !important;
}

.main-left-area {
  border-right: 1px solid #dcdfe6;
  width: 300px;
  min-height: 400px;
  overflow: outo;
}

.card {
  flex-basis: 400PX;
  /* 考虑 10px 的间隙，每个卡片占 20% 宽度 */
  height: 110px;
  box-sizing: border-box;
}


:deep(.el-card__body) {
  justify-content: normal !important;
  align-items: normal m !important
}
.search-operation-container {
  height: 32px;
  display: flex;
  align-items: center;
}
</style>
